1. /* sdftnhbs.cpp by K.Tsuru */
  2. // function ID 3327 DRADIX since ver 2.18
  3. /*****************************************
  4. SDouble class
  5. It provides hyperbolic tangent tanh(x)
  6. using binary splitting method.
  7. for large x rename "TanBS(x)" since version 2.21
  8. *****************************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. SDouble TanhBSLx(const SDouble& x){
  13. if(x.Sign(3327) == 0) return 0.0;
  14. double X = doubleD(x, 0);
  15. // check the condition "exp(2*x) < DRADIX^DRADIX_EXP_MAX".
  16. const double xMax = 0.5*(double)DFIGURES*M_LN10*(double)DRADIX_EXP_MAX; // = 301759.17.../2
  17. if( fabs(X) > xMax){ // exp(x) > D^(DRADIX_EXP_MAX)
  18. if(x.Sign() > 0) return 1.0;
  19. return -1.0;
  20. }
  21. SDouble r;
  22. if(x.NetRdxExp() <= 0){ // |x| < DRADIX, tanh x = sinh x/sqrt(1+sinh^2 x)
  23. r = SinhBS(x);
  24. r = r*RecSqrt(ONE+r*r);
  25. } else { //x >= DRADIX
  26. SDouble x2;
  27. x2 = DsMult(x, 2); // x2 = x*2
  28. if(x.Sign() > 0){
  29. x2 = DReciprocal(ONE + ExpBS(x2)); // x2 = 1/(1+exp(2*x))
  30. r = ONE - DsMult(x2, 2); // r = 1- 2/(1+exp(2*x))
  31. } else {
  32. x2 = DReciprocal(ONE + ExpBS(-x2)); // x2 = 1/(1+exp(-2*x))
  33. r = DsMult(x2, 2) - ONE; // r = 2/(1+exp(-2*x)) -1
  34. }
  35. }
  36. return r;
  37. }

sdftnhbs.cpp : last modifiled at 2016/08/29 16:48:07(1,229 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).